package org.jsola.hr.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.jsola.hr.entity.EmpInfoDO;
import org.jsola.hr.service.IEmpInfoService;
import org.jsola.user.core.TokenUser;
import org.jsola.user.service.IUserCallbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author Mr.Zheng
 */
@Service("hrUserCallbackServiceImpl")
@Slf4j
public class HrUserCallbackServiceImpl implements IUserCallbackService {

    @Autowired
    private IEmpInfoService empInfoService;


    @Override
    public void deleteUserCallback(List<String> userIds, TokenUser tokenUser) {
        // 删除用户 连同员工一起删除
        if (CollectionUtils.isEmpty(userIds)) {
            return;
        }
        // 查询User下员工 跨站点
        List<EmpInfoDO> empInfoDOList = empInfoService.selectByUserIds(userIds);
        if (!CollectionUtils.isEmpty(empInfoDOList)) {
            for (EmpInfoDO empInfoDO : empInfoDOList) {
                TokenUser deleteUser = new TokenUser(tokenUser.getUserId(), empInfoDO.getSiteId());
                empInfoService.deleteByIds(deleteUser, empInfoDO.getId());
            }
        }
    }
}
